package com.dk.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.params.SetParams;

public class UserLock {
    private static final String LOCKING="OK";
    private static final String LOCK="lock::";
    private static Jedis jedis=new Jedis("localhost",6379);

    private UserLock(){
    }

    /**
     * 用户锁  防止用户反复获取
     * @param uid
     */
    public static boolean lock(String uid){
        String s=jedis.set(LOCK+uid,LOCKING, SetParams.setParams().nx().ex(60));
        if(LOCKING.equals(s)){
            return true;
        }else return false;
    }

    public static boolean unlock(String uid){
        if(jedis.del(LOCK+uid)==0){
            return true;
        }else return false;
    }

}
